package org.example.springcloud.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JacksonUtil {

    /**
     * 字符串反序列化为对象
     * @param json
     * @param
     * @return
     * @param <T>
     * @throws JsonProcessingException
     */
    public static <T> T fromJson(String json, TypeReference<T> typeReference) throws JsonProcessingException {
        //json转对象
        ObjectMapper mapper = new ObjectMapper();
        T obj = mapper.readValue(json, typeReference);
        return obj;
    }
}
